package cn.matezk.cloud.controller;

import cn.hutool.json.JSONObject;
import cn.matezk.cloud.beans.Result;
import cn.matezk.cloud.service.IDeptService;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("miniApp")
public class DeptController {

    @Autowired
    private IDeptService deptService;

    @PostMapping("deptLoad")
    public Result deptLoad(@RequestBody JSONObject params) throws TencentCloudSDKException {
        deptService.load(params.getStr("AccessToken"), params.getLong("userId"));
        return Result.ok();
    }

    @PostMapping("AppCreateFamily")
    public Result appCreateFamily(@RequestBody JSONObject params, HttpServletRequest request) throws TencentCloudSDKException {
        params.set("Action", request.getRequestURI().split("/")[2]);
        JSONObject payload = deptService.appCreateFamily(params);
        return Result.data(payload);
    }

    @PostMapping("AppModifyFamily")
    public Result appModifyFamily(@RequestBody JSONObject params, HttpServletRequest request) throws TencentCloudSDKException {
        params.set("Action", request.getRequestURI().split("/")[2]);
        JSONObject payload = deptService.appModifyFamily(params);
        return Result.data(payload);
    }

    @PostMapping("AppDeleteFamily")
    public Result appDeleteFamily(@RequestBody JSONObject params, HttpServletRequest request) throws TencentCloudSDKException {
        params.set("Action", request.getRequestURI().split("/")[2]);
        JSONObject payload = deptService.appDeleteFamily(params);
        return Result.data(payload);
    }

    @PostMapping("AppCreateRoom")
    public Result appCreateRoom(@RequestBody JSONObject params, HttpServletRequest request) throws TencentCloudSDKException {
        params.set("Action", request.getRequestURI().split("/")[2]);
        JSONObject payload = deptService.appCreateRoom(params);
        return Result.data(payload);
    }

    @PostMapping("AppModifyRoom")
    public Result appModifyRoom(@RequestBody JSONObject params, HttpServletRequest request) throws TencentCloudSDKException {
        params.set("Action", request.getRequestURI().split("/")[2]);
        JSONObject payload = deptService.appModifyRoom(params);
        return Result.data(payload);
    }

    @PostMapping("AppDeleteRoom")
    public Result appDeleteRoom(@RequestBody JSONObject params, HttpServletRequest request) throws TencentCloudSDKException {
        params.set("Action", request.getRequestURI().split("/")[2]);
        JSONObject payload = deptService.appDeleteRoom(params);
        return Result.data(payload);
    }
}
